package com.qsw.paper.controller.user.student;


import com.qsw.paper.constant.MessageConstants;
import com.qsw.paper.pojo.dto.AdvisorUpdateTheseDto;
import com.qsw.paper.pojo.dto.TheseDto;
import com.qsw.paper.result.Result;
import com.qsw.paper.service.IThesesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qsw
 * @since 2024-11-15
 */
@RestController("userStudentThesesController")
@RequestMapping("/user/student/theses")
@RequiredArgsConstructor
@Slf4j
public class ThesesController {

    private final IThesesService thesesService;

    /**
     * 通过论文id 获取论文详细信息
     *
     * @param id 学生id
     * @return 论文实体
     */
    @GetMapping("/{id}")
    public Result<?> getTheseByTheseId(@PathVariable Integer id) {
        log.info("学生获取论文信息:{}", id);
        return Result.success(thesesService.getTheseByTheseId(id), MessageConstants.SELECT_OK);
    }

    /**
     * 修改论文信息
     *
     * @param thesisId 论文ID
     * @param theseDto 修改后的论文信息
     * @return 提示信息
     */
    @PutMapping("/{thesisId}")
    public Result<?> updateThesis(@PathVariable Integer thesisId, @RequestBody @Validated TheseDto theseDto) {
        log.info("学生修改论文：id={}, 修改内容={}", thesisId, theseDto);
        thesesService.update(thesisId, theseDto);
        return Result.success(MessageConstants.OPERATION_SUCCESSFUL);
    }

    /**
     * 添加论文
     *
     * @param theseDto dto
     * @return 提示
     */
    @PostMapping
    public Result<?> save(@RequestBody @Validated TheseDto theseDto) {
        log.info("学生添加论文:{}", theseDto);
        thesesService.save(theseDto);
        return Result.success(MessageConstants.ADD_OK);
    }

    /**
     * 根据学生id 获取学生提交的所有论文
     *
     * @param id 学生id
     * @return 论文列表
     */
    @GetMapping("/list/{id}")
    public Result<?> list(@PathVariable Integer id) {
        log.info("学生获取论文列表:{}", id);
        return Result.success(thesesService.list(id), MessageConstants.SELECT_OK);
    }

}
